<?php

namespace plugin\voice\app\controller;

use support\Request;
use support\Response;
use Webman\Medoo\Medoo as db;

class UserController{
    public function info(Request $request){
        $modelType   = [];
        $models      = db::select('voice_models',['field','name'],['status' => 1]);
        foreach ($models as $model) {
            $modelType[$model['field']] = $model['name'];
        }
        $newUserInfo = [];
        $userModels  = [];
        $userInfo    = $request->userInfo;
        $info        = [];
        foreach ($userInfo as $key => $value) {
            if (array_key_exists($key, $modelType)) {
                // $userModels[]      = [$modelType[$key] => $value];
                if($value){
                    $userModels[] = ['name' => $modelType[$key],'value' => $value];
                }
            } else {
                $newUserInfo[$key] = $value; // 如果不在映射关系中，则保持原样
            }
        }
        $newUserInfo['models'] = $userModels;
        return json([
            'cdoe' => 200,
            'msg'  => 'ok',
            'data' => $newUserInfo
        ]);
    }
    
}
